//
//  Conversation.swift
//  WeChatClient
//
//  Created by AI Assistant on 2025/10/31.
//

import Foundation

struct Conversation: Identifiable, Codable {
    let id = UUID()
    let participant: User
    var messages: [ChatMessage]
    var unreadCount: Int
    var lastMessage: ChatMessage? {
        return messages.last
    }
    var lastMessageTime: Date? {
        return lastMessage?.timestamp
    }
    
    init(participant: User, messages: [ChatMessage] = [], unreadCount: Int = 0) {
        self.participant = participant
        self.messages = messages
        self.unreadCount = unreadCount
    }
    
    mutating func addMessage(_ message: ChatMessage) {
        messages.append(message)
        if !message.isFromCurrentUser {
            unreadCount += 1
        }
    }
    
    mutating func markAsRead() {
        unreadCount = 0
    }
}
